import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children:[
      {
          path: '/',
          name: 'list',
          component: () => import('../views/list.vue')
      }, {
          path: '/list1',
          name: 'list1',
          component: () => import('../views/list1.vue')
      },{
          path: '/list2',
          name: 'list2',
          component: () => import('../views/list2.vue')
      }, {
          path: '/list3',
          name: 'list3',
          component: () => import('../views/list3.vue')
      }
    ]
  },
  {
    path: '/Cart',
    name: 'Cart',
    component: () => import('../views/Cart.vue')
  }
]

const router = new VueRouter({
  mode:'history',
  base: process.env.BASE_URL,
  routes
})
 
// 全局路由守卫
/**
 * to:将要切换的路由对象
 * from:即将离开的路由对象
 * next:下一步函数
 */
// router.beforeEach((to,from,next) => {
//   var userLocalstatus = localStorage.getItem("token");  
//   console.log(to);
//   if(to.name != "login") {
//     if(userLocalstatus){
//       next();
//     }else{    // 如果未登录
//       next("/login")
//     }
//   } else {
//     next();    //如果以上都没执行  直接放行
//   }
// })

export default router
